<!--退款申请驳回-->
<template>
  <el-dialog title="退款申请驳回" :visible.sync="visible" width="500px" :close-on-click-modal="false">

    <el-form ref="main-form" :model="form" :rules="rules" label-width="80px">

      <template v-if="!!item">
        <el-form-item label="订单号" size="mini" prop="tradeNo">
          <span>{{item.tradeNo}}</span>
        </el-form-item>

        <el-form-item label="商户号" size="mini" prop="tradeNo">
          <span>{{item.mchNo}}</span>
        </el-form-item>

        <el-form-item label="终端号" size="mini" prop="tradeNo">
          <span>{{item.terNo}}</span>
        </el-form-item>

        <el-form-item label="退款金额" size="mini" prop="tradeNo">
          <span>{{(item.amount / 100).toFixed(2)}} {{item.mchTransCurrency}}</span>
        </el-form-item>

      </template>

      <el-form-item label="驳回理由" size="mini" prop="reason">
        <el-input placeholder="" type="textarea" v-model="form.reason" @keyup.enter.native="submit"
                  clearable></el-input>
      </el-form-item>

    </el-form>

    <div slot="footer" class="dialog-footer">
      <!-- <el-popover
        v-if="id != null"
        placement="top"
        width="160"
        v-model="popDeleteVisible">
        <p>确定删除吗？</p>
        <div style="text-align: right; margin: 0">
          <el-button size="mini" type="default" @click="popDeleteVisible = false">取消</el-button>
          <el-button type="danger" size="mini" @click="submitDel">确定</el-button>
        </div>
        <el-button type="danger" slot="reference"  size="small" style="float: left;" :loading="loading">删 除</el-button>
      </el-popover> -->

      <el-button @click="close" size="small">取 消</el-button>
      <el-button type="danger" @click="submit" size="small" :loading="loading">驳 回</el-button>
    </div>

  </el-dialog>
</template>

<script>

  import ApiMain from '@/api/trade.refundApply'

  export default {

    data () {
      return {
        visible: false,
        loading: false,

        item: null,

        formRaw: null,
        form: {
          id: null,
          reason: null,
        },
        rules: {},
      }
    },

    mounted () {
      this.formRaw = Object.copy(this.form)
    },
    methods: {

      show (item) {

        this.reset()

        this.item = item
        this.visible = true

        this.form.id = this.item.id
      },

      close () {
        this.visible = false
        this.$emit('dialog-close')
      },

      reset () {
        this.form = Object.copy(this.formRaw)
      },

      verifyForm () {
        var bool = true
        this.$refs['main-form'].validate((valid) => bool = valid)
        return bool
      },

      async submit () {
        if (!this.verifyForm()) return false;

        this.loading = true;;

        try {
          var req = Object.copy(this.form);
          await ApiMain.reject(req);
          this.close();
          this.$message({message: '操作成功', type: 'success'});
        } catch (e) {}

        this.loading = false;

      },
    },
  }
</script>

<style scoped>

</style>
